/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.angholt.bookproject.db.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;


/**
 * Entity class to store informashen about user.
 * @author Patric Peterson
 */
@Entity(name="book_user")
public class User implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long userId;
    
    @Column(length=127)
    private String name;
    
    //specifying whether user is active, inactive, banned or other notifications. 
    //This is not implemented in this version. 
    @Column(nullable=false,length=15)
    private String state; // TODO : move to enum class
    
    @Column(nullable=true,length=255,unique=true)
    private String email;
    
    @Column(nullable=false)
    private int hash;
  
    
    /**
     * Construct a user class with all basic data.
     * @param name The name of the user. ( less then 127 chars )
     * @param state The state of the user. ( less then 15 chars )
     * @param email The email of the user. ( less then 255 chars )
     * @param hash The hash of the user.
     */
    public User(String name, String state, String email, int hash) {
        this.name = name;
        this.state = state;
        this.email = email;
        this.hash = hash;
       
    }

    /**
     * Construct a Author class with no data
     * need to add email, hash, name, stat.
     */   
    public User() {
        
    }

    /**
      * Get entity id.
      * @return entity id.
      */
    public Long getUserId() {
        return userId;
    }

    /**
     * set entity id.
     * shout not be changed exept by jpa.
     * @param id entity id
     */
    public void setUserId(Long id) {
        this.userId = id;
    }

    /**
     * Get the email addres of the user.
     * @return Email addres of the user.
     */
    public String getEmail() {
        return email;
    }

    /**
     * Set the email addres of the user. ( less then 255 chars )
     * @param email Email addres of the user.
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Get the hash of the user.
     * @return Hash of the user.
     */
    public int getHash() {
        return hash;
    }

    /**
     * Set the hash of the user.
     * @param hash Hash of the user.
     */
    public void setHash(int hash) {
        this.hash = hash;
    }

    /**
     * Get the name of the user.
     * @return Name of user.
     */
    public String getName() {
        return name;
    }

    /**
     * Set the name of the user ( less then 127 chars )
     * @param name Name of user.
     */
    public void setName(String name) {
        this.name = name;
    }

    /** 
     * Not used
     * Get the state of the user.
     * @return State of the user.
     */ 
    public String getState() {
        return state;
    }

    /**
     * Not used
     * Set the state of the user.
     * @param state State of the user.
     */
    public void setState(String state) {
        this.state = state;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TO DO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.angholt.bookproject.db.entity.User[ id=" + userId + " ]";
    }
    
}
